import pygame, random
from pygame.locals import *
from source.Constant import *
from source.Player import *
from source.Goblin import *
from source.Wall import *

class Game:
    def __init__(self):
        pygame.display.set_caption(CAPTION)
        self.screen = pygame.display.set_mode(RESOLUTION)
        
        self.all = pygame.sprite.RenderUpdates()
        self.walls = pygame.sprite.RenderClear()
        self.goblins = pygame.sprite.RenderClear()
        
        Player.containers = self.all
        Wall.containers = self.all, self.walls
        Goblin.containers = self.all, self.goblins
        
        self.player = Player()
        
        self.clock = pygame.time.Clock()
        self.lives = 3
        
    def Menu(self):
        pass
        #Menu not implemented.
        
    def Gameloop(self):
        self.clock.tick(45)
        #Currently not implementing the rest of the game
        #loop just setting up the collisions.
        
        while 1:
            
            wallcollide = pygame.sprite.spritecollide(self.player, self.walls,0)
            for c in wallcollide:
                if self.player.colliderect(self.walls.rect.left):
                    self.player.centerx += 1
                if self.player.colliderect(self.walls.rect.right):
                    self.player.centerx -= 1
                if self.player.colliderect(self.walls.rect.up):
                    self.player.centery -= 1
                if self.player.colliderect(self.walls.rect.bottom):
                    self.player.centery += 1

            if pygame.sprite.spritecollide(self.player, self.goblins,0):
                self.player.kill()
                self.lives -= 1
                self.player = Player()
                
            